/**
* @file 秒杀详情
* @author 张超
* @created 2023/6/30 17:00
* @updated 2023/7/27 18:00
*/
<template>
	<view class="seckill-detail">
		<u-navbar :border-bottom="false" title-size="35" title="商品详情"></u-navbar>
		<image class="detail-img" :src="detailDa.goodsimage_text"></image>
		<view class="detail-cont">
			<view class="cont-des1">
				<view class="left">
					<view>
						<text>{{detailDa.sgoodsprice | xiaos}}</text>
						<text>金币+</text>
						<text>{{detailDa.sgoodssalenum | xiaos}}</text>
						<text>积分</text>
					</view>
					<text>{{detailDa.goodsprice | xiaos}}金币+{{detailDa.goodssalenum | xiaos}}积分</text>
				</view>
				<view class="right">
					<text>{{istype==2?'距离开抢时间':istype==1?'限时秒杀':'活动已结束'}}</text>
					<uni-countdown v-if="istype!=3" :day="time.days" :hour="time.hours" :minute="time.minutes"
						:second="time.seconds" color="#000" @timeup="timeupEv" background-color="#FFFFFF" />
				</view>
			</view>
			<view class="cont-des2">
				{{detailDa.goodsname}}
			</view>
			<view class="cont-des3">
				<view class="">
					<text>销量</text>
					<text>{{detailDa.salenum}}</text>
				</view>
				<view class="">
					<text>运费</text>
					<text>免运费</text>
				</view>
				<view class="">
					<text>参数</text>
					<text>{{detailDa.parameters}}</text>
				</view>
			</view>
			<view class="comment-section">
			  <view class="comment-header">
			    <text class="title">商品评价</text>
			    <view class="view-all" @click="goToCommentList">
			      <text>查看全部</text>
			      <u-icon name="arrow-right" color="#999" size="24"></u-icon>
			    </view>
			  </view>
			  
			  <view class="comment-empty">
			    <text>暂无评价</text>
			    <text class="hint">还没有人评价过该商品</text>
			  </view>
			  
			  <view class="comment-stats">
			    <view class="stat-item">
			      <text class="value">0</text>
			      <text class="label">评价总数</text>
			    </view>
			    <view class="stat-item">
			      <text class="value">0%</text>
			      <text class="label">好评率</text>
			    </view>
			  </view>
			</view>
		</view>
		<view class="cont-poster">
			<u-parse :html="detailDa.goodscontent_text" style="font-size: 0;"></u-parse>
		</view>
		<view class="" style="height:150rpx"></view>
		<!-- 即将开抢 -->
		<view class="promptly" @click="config" :class="isre?'promptlyew':''">
			<view>{{show?'即将购买':'立即购买'}}</view>
		</view>
	</view>
</template>

<script>
	import {
		goods_detail,
		goods_list,
		goods_price
	} from '@/network/api.js'
	export default {
		data() {
			return {
				// 即将开抢和立即秒杀切换
				show: false,
				// 详情id
				ids: '',
				// 详情数据
				detailDa: {},
				// 倒计时
				time: {},
				// 海报数据
				content: ``,
				isre:true,
				istype:'',//2距离抢购开始时间，1抢购倒计时
			}
		},
		onLoad(option) {
			this.ids = option.id
			this.detailRe()
		},
		filters: {
			// 过滤小数点后面数据
			xiaos(num) {
				return Math.trunc(num)
			},
		},
		methods: {
			// 跳转到评论列表
			  goToCommentList() {
			    uni.navigateTo({
			      url: `/pages/subpackage/shop/commentList?id=${this.ids}`
			    })
			  },
			// 时间戳转换为时间
			calculateTimeDifference(timestamp1, timestamp2) {
				const difference = Math.abs(timestamp1 - timestamp2);
				const days = Math.floor(difference / (24 * 60 * 60 * 1000));
				const hours = Math.floor((difference % (24 * 60 * 60 * 1000)) / (60 * 60 * 1000));
				const minutes = Math.floor((difference % (60 * 60 * 1000)) / (60 * 1000));
				const seconds = Math.floor((difference % (60 * 1000)) / 1000);

				return {
					days,
					hours,
					minutes,
					seconds
				};
			},
			timeupEv(){
				// let startime = new Date().getTime()
				// if(this.detailDa.kill_end<startime){
				// 	console.log('触发')
					this.isre=true
				// }
			},
			// 获取秒杀详情数据
			detailRe() {
				let data = {
					id: this.ids
				}
				goods_detail(data).then(res => {
					this.detailDa = res.data
					// 当前时间戳
					let times = new Date().getTime()
					// 结束时间戳
					let endtime = this.detailDa.kill_end * 1000
					let startime = this.detailDa.kill_begin * 1000
					// let startime=1714878117*1000
					// let endtime=1714952217*1000  
					if(times>startime&&times<endtime){
						console.log('触发1')
						this.isre=false
						this.istype=1
						this.time = this.calculateTimeDifference(times, endtime)
						return ;
					}
					if(times<startime){
						console.log('触发2')
						this.isre=true
						this.istype=2
						this.time = this.calculateTimeDifference(times, startime)
						return ;
					}
					if(times>endtime){
						console.log('触发3')
						this.istype=3
						return ;
					}
				})
			},
			// 确定
			config() {
				if(!this.isre){
					let data={
						type:2,
						number:1,
						market:this.detailDa
					}
					uni.navigateTo({
						url: '/pages/subpackage/shop/config?data='+JSON.stringify(data)
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	// 处理富文本间隔问题
	.u-parse .p {
		padding: 0 !important;
	}

	.u-parse view {
		line-height: 0 !important;
	}

	.uni-countdown {
		opacity: 0.6;
	}

	.img {
		border: 1rpx solid red;
	}

	.seckill-detail {
		background-color: #f7f7f7;

		.detail-img {
			width: 100%;
			height: 650rpx;
		}

		.detail-cont {
			padding: 10rpx 20rpx;

			.cont-des1 {
				position: relative;
				left: 0;
				right: 0;
				display: flex;
				justify-content: space-between;
				height: 120rpx;
				margin: -100rpx 20rpx 20rpx 20rpx;
				padding: 10rpx 20rpx;
				border-radius: 15rpx;
				background-color: #fff;
				background: linear-gradient(to right, #FF4F4C, #FF120E);

				.left {
					color: #fff;
					box-sizing: border-box;

					>view {
						>text:nth-child(odd) {
							font-size: 40rpx;
							font-family: PingFang SC, PingFang SC-Medium;
							font-weight: bold;
						}
					}

					>text {
						text-decoration: line-through;
						font-family: PingFang SC, PingFang SC-Medium;
					}
				}

				.right {
					>text:nth-child(1) {
						margin-left: 80rpx;
						font-size: 28rpx;
						color: #fff;

					}

					>text:nth-child(2) {
						display: block;
						text-align: center;
						width: 56px;
						height: 18px;
						margin-top: 10rpx;
						font-size: 22rpx;
						background: #f4a034;
						border-radius: 1.5px;
					}
				}
			}

			.cont-des2 {
				height: 108rpx;
				line-height: 108rpx;
				margin: 0 20rpx;
				padding: 0rpx 20rpx;
				background: #ffffff;
				border-radius: 15rpx;
				font-size: 30rpx;
				font-family: PingFang SC, PingFang SC-Medium;
				font-weight: bold;
			}

			.cont-des3 {
				margin: 20rpx;

				>view {
					height: 108rpx;
					line-height: 108rpx;
					padding: 0rpx 20rpx;
					background: #ffffff;
					box-sizing: border-box;
					border-bottom: 1rpx solid #EEEEEE;

					>text:nth-child(1) {
						margin-right: 40rpx;
					}

					>text:nth-child(2) {
						color: #666666
					}
				}

				>view:nth-child(1) {
					border-top-left-radius: 15rpx;
					border-top-right-radius: 15rpx;
				}

				>view:nth-child(2) {
					border-bottom-left-radius: 15rpx;
					border-bottom-right-radius: 15rpx;
				}

				>view:nth-child(2) {
					border: none
				}
			}

			.cont-poster {}
		}

		//即将开抢
		
		.promptlyew{
			>view{
				color: black !important;
				background-color: #f5f5f5 !important
			}
		}
		.promptly {
			position: fixed;
			left: 0;
			right: 0;
			bottom: 0rpx;
			height: 140rpx;
			text-align: center;
			margin-top: 40rpx;
			padding: 30rpx 22rpx;
			background-color: #fff;

			>view {
				display: block;
				height: 90rpx;
				line-height: 90rpx;
				color: #fff;
				border-radius: 10rpx;
				background-color: #F4A034;
			}

			>view:active {
				background-color: #e9cba9;
			}
		}
	}
	// 在现有样式后添加
	.comment-section {
	  background-color: #fff;
	  padding: 30rpx;
	  margin: 20rpx;
	  border-radius: 15rpx;
	  
	  .comment-header {
	    display: flex;
	    justify-content: space-between;
	    align-items: center;
	    margin-bottom: 30rpx;
	    
	    .title {
	      font-size: 32rpx;
	      font-weight: bold;
	      color: #333;
	    }
	    
	    .view-all {
	      display: flex;
	      align-items: center;
	      font-size: 26rpx;
	      color: #999;
	      
	      text {
	        margin-right: 10rpx;
	      }
	    }
	  }
	  
	  .comment-empty {
	    display: flex;
	    flex-direction: column;
	    align-items: center;
	    padding: 40rpx 0;
	    
	    text {
	      font-size: 28rpx;
	      color: #666;
	    }
	    
	    .hint {
	      font-size: 24rpx;
	      color: #999;
	      margin-top: 10rpx;
	    }
	  }
	  
	  .comment-stats {
	    display: flex;
	    justify-content: space-around;
	    margin-top: 30rpx;
	    padding-top: 30rpx;
	    border-top: 1rpx solid #eee;
	    
	    .stat-item {
	      display: flex;
	      flex-direction: column;
	      align-items: center;
	      
	      .value {
	        font-size: 36rpx;
	        font-weight: bold;
	        color: #333;
	        margin-bottom: 10rpx;
	      }
	      
	      .label {
	        font-size: 26rpx;
	        color: #666;
	      }
	    }
	  }
	}
</style>